from django import forms
from student.models import Student,StudentDetail


class StudentForm(forms.ModelForm):
    class Meta:
        model = Student
        exclude = ['is_delete']
        widgets = {
            'sex': forms.RadioSelect()
        }


class StudentDetailForm(forms.ModelForm):
    class Meta:
        model = StudentDetail
        exclude = ['student']

    def clean_num(self):
        data = self.cleaned_data.get('num')
        if not data[:-1].isdigit():
            # self.add_error('num', '输入的身份证号码有误！')
            raise forms.ValidationError('输入的身份证号码有误！')
        return data
